home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / public / GNU / emacs.inst / emacs19.idb / usr / gnu / info / elisp-4.z / elisp-4
Encoding:
GNU Info File  |  1994-08-02  |  48.1 KB  |  1,295 lines

  1. This is Info file elisp, produced by Makeinfo-1.55 from the input file
  2. elisp.texi.
  3.  
  4.    This version is newer than the second printed edition of the GNU
  5. Emacs Lisp Reference Manual.  It corresponds to Emacs Version 19.19.
  6.  
  7.    Published by the Free Software Foundation 675 Massachusetts Avenue
  8. Cambridge, MA 02139 USA
  9.  
  10.    Copyright (C) 1990, 1991, 1992, 1993 Free Software Foundation, Inc.
  11.  
  12.    Permission is granted to make and distribute verbatim copies of this
  13. manual provided the copyright notice and this permission notice are
  14. preserved on all copies.
  15.  
  16.    Permission is granted to copy and distribute modified versions of
  17. this manual under the conditions for verbatim copying, provided that
  18. the entire resulting derived work is distributed under the terms of a
  19. permission notice identical to this one.
  20.  
  21.    Permission is granted to copy and distribute translations of this
  22. manual into another language, under the above conditions for modified
  23. versions, except that this permission notice may be stated in a
  24. translation approved by the Foundation.
  25.  
  26.    Permission is granted to copy and distribute modified versions of
  27. this manual under the conditions for verbatim copying, provided also
  28. that the section entitled "GNU Emacs General Public License" is included
  29. exactly as in the original, and provided that the entire resulting
  30. derived work is distributed under the terms of a permission notice
  31. identical to this one.
  32.  
  33.    Permission is granted to copy and distribute translations of this
  34. manual into another language, under the above conditions for modified
  35. versions, except that the section entitled "GNU Emacs General Public
  36. License" may be included in a translation approved by the Free Software
  37. Foundation instead of in the original English.
  38.  
  39. 
  40. File: elisp,  Node: Predicates on Numbers,  Next: Comparison of Numbers,  Prev: Float Basics,  Up: Numbers
  41.  
  42. Type Predicates for Numbers
  43. ===========================
  44.  
  45.    The functions in this section test whether the argument is a number
  46. or whether it is a certain sort of number.  The functions `integerp'
  47. and `floatp' can take any type of Lisp object as argument (the
  48. predicates would not be of much use otherwise); but the `zerop'
  49. predicate requires a number as its argument.  See also
  50. `integer-or-marker-p' and `number-or-marker-p', in *Note Predicates on
  51. Markers::.
  52.  
  53.  - Function: floatp OBJECT
  54.      This predicate tests whether its argument is a floating point
  55.      number and returns `t' if so, `nil' otherwise.
  56.  
  57.      `floatp' does not exist in Emacs versions 18 and earlier.
  58.  
  59.  - Function: integerp OBJECT
  60.      This predicate tests whether its argument is an integer, and
  61.      returns `t' if so, `nil' otherwise.
  62.  
  63.  - Function: numberp OBJECT
  64.      This predicate tests whether its argument is a number (either
  65.      integer or floating point), and returns `t' if so, `nil' otherwise.
  66.  
  67.  - Function: natnump OBJECT
  68.      The `natnump' predicate (whose name comes from the phrase
  69.      "natural-number-p") tests to see whether its argument is a
  70.      nonnegative integer, and returns `t' if so, `nil' otherwise.  0 is
  71.      considered non-negative.
  72.  
  73.      Markers are not converted to integers, hence `natnump' of a marker
  74.      is always `nil'.
  75.  
  76.      People have pointed out that this function is misnamed, because
  77.      the term "natural number" is usually understood as excluding zero.
  78.      We are open to suggestions for a better name to use in a future
  79.      version.
  80.  
  81.  - Function: zerop NUMBER
  82.      This predicate tests whether its argument is zero, and returns `t'
  83.      if so, `nil' otherwise.  The argument must be a number.
  84.  
  85.      These two forms are equivalent: `(zerop x) == (= x 0)'.
  86.  
  87. 
  88. File: elisp,  Node: Comparison of Numbers,  Next: Numeric Conversions,  Prev: Predicates on Numbers,  Up: Numbers
  89.  
  90. Comparison of Numbers
  91. =====================
  92.  
  93.    Floating point numbers in Emacs Lisp actually take up storage, and
  94. there can be many distinct floating point number objects with the same
  95. numeric value.  If you use `eq' to compare them, then you test whether
  96. two values are the same *object*.  If you want to compare just the
  97. numeric values, use `='.
  98.  
  99.    If you use `eq' to compare two integers, it always returns `t' if
  100. they have the same value.  This is sometimes useful, because `eq'
  101. accepts arguments of any type and never causes an error, whereas `='
  102. signals an error if the arguments are not numbers or markers.  However,
  103. it is a good idea to use `=' if you can, even for comparing integers,
  104. just in case we change the representation of integers in a future Emacs
  105. version.
  106.  
  107.    There is another wrinkle: because floating point arithmetic is not
  108. exact, it is often a bad idea to check for equality of two floating
  109. point values.  Usually it is better to test for approximate equality.
  110. Here's a function to do this:
  111.  
  112.      (defvar fuzz-factor 1.0e-6)
  113.      
  114.      (defun approx-equal (x y)
  115.        (< (/ (abs (- x y))
  116.              (max (abs x) (abs y)))
  117.           fuzz-factor))
  118.  
  119.      Common Lisp note: because of the way numbers are implemented in
  120.      Common Lisp, you generally need to use ``='' to test for equality
  121.      between numbers of any kind.
  122.  
  123.  - Function: = NUMBER-OR-MARKER1 NUMBER-OR-MARKER2
  124.      This function tests whether its arguments are the same number, and
  125.      returns `t' if so, `nil' otherwise.
  126.  
  127.  - Function: /= NUMBER-OR-MARKER1 NUMBER-OR-MARKER2
  128.      This function tests whether its arguments are not the same number,
  129.      and returns `t' if so, `nil' otherwise.
  130.  
  131.  - Function: < NUMBER-OR-MARKER1 NUMBER-OR-MARKER2
  132.      This function tests whether its first argument is strictly less
  133.      than its second argument.  It returns `t' if so, `nil' otherwise.
  134.  
  135.  - Function: <= NUMBER-OR-MARKER1 NUMBER-OR-MARKER2
  136.      This function tests whether its first argument is less than or
  137.      equal to its second argument.  It returns `t' if so, `nil'
  138.      otherwise.
  139.  
  140.  - Function: > NUMBER-OR-MARKER1 NUMBER-OR-MARKER2
  141.      This function tests whether its first argument is strictly greater
  142.      than its second argument.  It returns `t' if so, `nil' otherwise.
  143.  
  144.  - Function: >= NUMBER-OR-MARKER1 NUMBER-OR-MARKER2
  145.      This function tests whether its first argument is greater than or
  146.      equal to its second argument.  It returns `t' if so, `nil'
  147.      otherwise.
  148.  
  149.  - Function: max NUMBER-OR-MARKER &rest NUMBERS-OR-MARKERS
  150.      This function returns the largest of its arguments.
  151.  
  152.           (max 20)
  153.                => 20
  154.           (max 1 2)
  155.                => 2
  156.           (max 1 3 2)
  157.                => 3
  158.  
  159.  - Function: min NUMBER-OR-MARKER &rest NUMBERS-OR-MARKERS
  160.      This function returns the smallest of its arguments.
  161.  
  162. 
  163. File: elisp,  Node: Numeric Conversions,  Next: Arithmetic Operations,  Prev: Comparison of Numbers,  Up: Numbers
  164.  
  165. Numeric Conversions
  166. ===================
  167.  
  168.    To convert an integer to floating point, use the function `float'.
  169.  
  170.  - Function: float NUMBER
  171.      This returns NUMBER converted to floating point.  If NUMBER is
  172.      already a floating point number, `float' returns it unchanged.
  173.  
  174.    There are four functions to convert floating point numbers to
  175. integers; they differ in how they round.  You can call these functions
  176. with an integer argument also; if you do, they return it without change.
  177.  
  178.  - Function: truncate NUMBER
  179.      This returns NUMBER, converted to an integer by rounding towards
  180.      zero.
  181.  
  182.  - Function: floor NUMBER &optional DIVISOR
  183.      This returns NUMBER, converted to an integer by rounding downward
  184.      (towards negative infinity).
  185.  
  186.      If DIVISOR is specified, NUMBER is divided by DIVISOR before the
  187.      floor is taken; this is the division operation that corresponds to
  188.      `mod'.  An `arith-error' results if DIVISOR is 0.
  189.  
  190.  - Function: ceiling NUMBER
  191.      This returns NUMBER, converted to an integer by rounding upward
  192.      (towards positive infinity).
  193.  
  194.  - Function: round NUMBER
  195.      This returns NUMBER, converted to an integer by rounding towards
  196.      the nearest integer.
  197.  
  198. 
  199. File: elisp,  Node: Arithmetic Operations,  Next: Bitwise Operations,  Prev: Numeric Conversions,  Up: Numbers
  200.  
  201. Arithmetic Operations
  202. =====================
  203.  
  204.    Emacs Lisp provides the traditional four arithmetic operations:
  205. addition, subtraction, multiplication, and division.  Remainder and
  206. modulus functions supplement the division functions.  The functions to
  207. add or subtract 1 are provided because they are traditional in Lisp and
  208. commonly used.
  209.  
  210.    All of these functions except `%' return a floating point value if
  211. any argument is floating.
  212.  
  213.    It is important to note that in GNU Emacs Lisp, arithmetic functions
  214. do not check for overflow.  Thus `(1+ 8388607)' may equal -8388608,
  215. depending on your hardware.
  216.  
  217.  - Function: 1+ NUMBER-OR-MARKER
  218.      This function returns NUMBER-OR-MARKER plus 1.  For example,
  219.  
  220.           (setq foo 4)
  221.                => 4
  222.           (1+ foo)
  223.                => 5
  224.  
  225.      This function is not analogous to the C operator `++'--it does not
  226.      increment a variable.  It just computes a sum.  Thus,
  227.  
  228.           foo
  229.                => 4
  230.  
  231.      If you want to increment the variable, you must use `setq', like
  232.      this:
  233.  
  234.           (setq foo (1+ foo))
  235.                => 5
  236.  
  237.  - Function: 1- NUMBER-OR-MARKER
  238.      This function returns NUMBER-OR-MARKER minus 1.
  239.  
  240.  - Function: abs NUMBER
  241.      This returns the absolute value of NUMBER.
  242.  
  243.  - Function: + &rest NUMBERS-OR-MARKERS
  244.      This function adds its arguments together.  When given no
  245.      arguments, `+' returns 0.  It does not check for overflow.
  246.  
  247.           (+)
  248.                => 0
  249.           (+ 1)
  250.                => 1
  251.           (+ 1 2 3 4)
  252.                => 10
  253.  
  254.  - Function: - &optional NUMBER-OR-MARKER &rest OTHER-NUMBERS-OR-MARKERS
  255.      The `-' function serves two purposes: negation and subtraction.
  256.      When `-' has a single argument, the value is the negative of the
  257.      argument.  When there are multiple arguments, each of the
  258.      OTHER-NUMBERS-OR-MARKERS is subtracted from NUMBER-OR-MARKER,
  259.      cumulatively.  If there are no arguments, the result is 0.  This
  260.      function does not check for overflow.
  261.  
  262.           (- 10 1 2 3 4)
  263.                => 0
  264.           (- 10)
  265.                => -10
  266.           (-)
  267.                => 0
  268.  
  269.  - Function: * &rest NUMBERS-OR-MARKERS
  270.      This function multiplies its arguments together, and returns the
  271.      product.  When given no arguments, `*' returns 1.  It does not
  272.      check for overflow.
  273.  
  274.           (*)
  275.                => 1
  276.           (* 1)
  277.                => 1
  278.           (* 1 2 3 4)
  279.                => 24
  280.  
  281.  - Function: / DIVIDEND DIVISOR &rest DIVISORS
  282.      This function divides DIVIDEND by DIVISORS and returns the
  283.      quotient.  If there are additional arguments DIVISORS, then
  284.      DIVIDEND is divided by each divisor in turn.  Each argument may be
  285.      a number or a marker.
  286.  
  287.      If all the arguments are integers, then the result is an integer
  288.      too.  This means the result has to be rounded.  On most machines,
  289.      the result is rounded towards zero after each division, but some
  290.      machines may round differently with negative arguments.  This is
  291.      because the Lisp function `/' is implemented using the C division
  292.      operator, which has the same possibility for machine-dependent
  293.      rounding.  As a practical matter, all known machines round in the
  294.      standard fashion.
  295.  
  296.      If you divide by 0, an `arith-error' error is signaled.  (*Note
  297.      Errors::.)
  298.  
  299.           (/ 6 2)
  300.                => 3
  301.           (/ 5 2)
  302.                => 2
  303.           (/ 25 3 2)
  304.                => 4
  305.           (/ -17 6)
  306.                => -2
  307.  
  308.      Since the division operator in Emacs Lisp is implemented using the
  309.      division operator in C, the result of dividing negative numbers
  310.      may in principle vary from machine to machine, depending on how
  311.      they round the result.  Thus, the result of `(/ -17 6)' could be
  312.      -3 on some machines.  In practice, all known machines round the
  313.      quotient towards 0.
  314.  
  315.  - Function: % DIVIDEND DIVISOR
  316.      This function returns the integer remainder after division of
  317.      DIVIDEND by DIVISOR.  The arguments must be integers or markers.
  318.  
  319.      For negative arguments, the value is in principle machine-dependent
  320.      since the quotient is; but in practice, all known machines behave
  321.      alike.
  322.  
  323.      An `arith-error' results if DIVISOR is 0.
  324.  
  325.           (% 9 4)
  326.                => 1
  327.           (% -9 4)
  328.                => -1
  329.           (% 9 -4)
  330.                => 1
  331.           (% -9 -4)
  332.                => -1
  333.  
  334.      For any two integers DIVIDEND and DIVISOR,
  335.  
  336.           (+ (% DIVIDEND DIVISOR)
  337.              (* (/ DIVIDEND DIVISOR) DIVISOR))
  338.  
  339.      always equals DIVIDEND.
  340.  
  341.  - Function: mod DIVIDEND DIVISOR
  342.      This function returns the value of DIVIDEND modulo DIVISOR; in
  343.      other words, the remainder after division of DIVIDEND by DIVISOR,
  344.      but with the same sign as DIVISOR.  The arguments must be numbers
  345.      or markers.
  346.  
  347.      Unlike `%', the result is well-defined for negative arguments.
  348.      Also, floating point arguments are permitted.
  349.  
  350.      An `arith-error' results if DIVISOR is 0.
  351.  
  352.           (mod 9 4)
  353.                => 1
  354.           (mod -9 4)
  355.                => 3
  356.           (mod 9 -4)
  357.                => -3
  358.           (mod -9 -4)
  359.                => -1
  360.  
  361.      For any two numbers DIVIDEND and DIVISOR,
  362.  
  363.           (+ (mod DIVIDEND DIVISOR)
  364.              (* (floor DIVIDEND DIVISOR) DIVISOR))
  365.  
  366.      always equals DIVIDEND, subject to rounding error if either
  367.      argument is floating point.
  368.  
  369. 
  370. File: elisp,  Node: Bitwise Operations,  Next: Transcendental Functions,  Prev: Arithmetic Operations,  Up: Numbers
  371.  
  372. Bitwise Operations on Integers
  373. ==============================
  374.  
  375.    In a computer, an integer is represented as a binary number, a
  376. sequence of "bits" (digits which are either zero or one).  A bitwise
  377. operation acts on the individual bits of such a sequence.  For example,
  378. "shifting" moves the whole sequence left or right one or more places,
  379. reproducing the same pattern "moved over".
  380.  
  381.    The bitwise operations in Emacs Lisp apply only to integers.
  382.  
  383.  - Function: lsh INTEGER1 COUNT
  384.      `lsh', which is an abbreviation for "logical shift", shifts the
  385.      bits in INTEGER1 to the left COUNT places, or to the right if
  386.      COUNT is negative.  If COUNT is negative, `lsh' shifts zeros into
  387.      the most-significant bit, producing a positive result even if
  388.      INTEGER1 is negative.  Contrast this with `ash', below.
  389.  
  390.      Thus, the decimal number 5 is the binary number 00000101.  Shifted
  391.      once to the left, with a zero put in the one's place, the number
  392.      becomes 00001010, decimal 10.
  393.  
  394.      Here are two examples of shifting the pattern of bits one place to
  395.      the left.  Since the contents of the rightmost place has been
  396.      moved one place to the left, a value has to be inserted into the
  397.      rightmost place.  With `lsh', a zero is placed into the rightmost
  398.      place.  (These examples show only the low-order eight bits of the
  399.      binary pattern; the rest are all zero.)
  400.  
  401.           (lsh 5 1)
  402.                => 10
  403.           
  404.           ;; Decimal 5 becomes decimal 10.
  405.           00000101 => 00001010
  406.           
  407.           (lsh 7 1)
  408.                => 14
  409.           
  410.           ;; Decimal 7 becomes decimal 14.
  411.           00000111 => 00001110
  412.  
  413.      As the examples illustrate, shifting the pattern of bits one place
  414.      to the left produces a number that is twice the value of the
  415.      previous number.
  416.  
  417.      Note, however that functions do not check for overflow, and a
  418.      returned value may be negative (and in any case, no more than a 24
  419.      bit value) when an integer is sufficiently left shifted.
  420.  
  421.      For example, left shifting 8,388,607 produces -2:
  422.  
  423.           (lsh 8388607 1)          ; left shift
  424.                => -2
  425.  
  426.      In binary, in the 24 bit implementation, the numbers looks like
  427.      this:
  428.  
  429.           ;; Decimal 8,388,607
  430.           0111 1111  1111 1111  1111 1111
  431.  
  432.      which becomes the following when left shifted:
  433.  
  434.           ;; Decimal -2
  435.           1111 1111  1111 1111  1111 1110
  436.  
  437.      Shifting the pattern of bits two places to the left produces
  438.      results like this (with 8-bit binary numbers):
  439.  
  440.           (lsh 3 2)
  441.                => 12
  442.           
  443.           ;; Decimal 3 becomes decimal 12.
  444.           00000011 => 00001100
  445.  
  446.      On the other hand, shifting the pattern of bits one place to the
  447.      right looks like this:
  448.  
  449.           (lsh 6 -1)
  450.                => 3
  451.           
  452.           ;; Decimal 6 becomes decimal 3.
  453.           00000110 => 00000011
  454.           
  455.           (lsh 5 -1)
  456.                => 2
  457.           
  458.           ;; Decimal 5 becomes decimal 2.
  459.           00000101 => 00000010
  460.  
  461.      As the example illustrates, shifting the pattern of bits one place
  462.      to the right divides the value of the binary number by two,
  463.      rounding downward.
  464.  
  465.  - Function: ash INTEGER1 COUNT
  466.      `ash' ("arithmetic shift") shifts the bits in INTEGER1 to the left
  467.      COUNT places, or to the right if COUNT is negative.
  468.  
  469.      `ash' gives the same results as `lsh' except when INTEGER1 and
  470.      COUNT are both negative.  In that case, `ash' puts a one in the
  471.      leftmost position, while `lsh' puts a zero in the leftmost
  472.      position.
  473.  
  474.      Thus, with `ash', shifting the pattern of bits one place to the
  475.      right looks like this:
  476.  
  477.           (ash -6 -1)
  478.                => -3
  479.           
  480.           ;; Decimal -6
  481.           ;; becomes decimal -3.
  482.           
  483.           1111 1111  1111 1111  1111 1010
  484.                =>
  485.           1111 1111  1111 1111  1111 1101
  486.  
  487.      In contrast, shifting the pattern of bits one place to the right
  488.      with `lsh' looks like this:
  489.  
  490.           (lsh -6 -1)
  491.                => 8388605
  492.           
  493.           ;; Decimal -6
  494.           ;; becomes decimal 8,388,605.
  495.           
  496.           1111 1111  1111 1111  1111 1010
  497.                =>
  498.           0111 1111  1111 1111  1111 1101
  499.  
  500.      In this case, the 1 in the leftmost position is shifted one place
  501.      to the right, and a zero is shifted into the leftmost position.
  502.  
  503.      Here are other examples:
  504.  
  505.           ;               24-bit binary values
  506.           
  507.           (lsh 5 2)          ;   5  =  0000 0000  0000 0000  0000 0101
  508.                => 20         ;  20  =  0000 0000  0000 0000  0001 0100
  509.  
  510.           (ash 5 2)
  511.                => 20
  512.           (lsh -5 2)         ;  -5  =  1111 1111  1111 1111  1111 1011
  513.                => -20        ; -20  =  1111 1111  1111 1111  1110 1100
  514.           (ash -5 2)
  515.                => -20
  516.  
  517.           (lsh 5 -2)         ;   5  =  0000 0000  0000 0000  0000 0101
  518.                => 1          ;   1  =  0000 0000  0000 0000  0000 0001
  519.  
  520.           (ash 5 -2)
  521.                => 1
  522.  
  523.           (lsh -5 -2)        ;  -5  =  1111 1111  1111 1111  1111 1011
  524.                => 4194302    ;         0011 1111  1111 1111  1111 1110
  525.  
  526.           (ash -5 -2)        ;  -5  =  1111 1111  1111 1111  1111 1011
  527.                => -2         ;  -2  =  1111 1111  1111 1111  1111 1110
  528.  
  529.  - Function: logand &rest INTS-OR-MARKERS
  530.      This function returns the "logical and" of the arguments: the Nth
  531.      bit is set in the result if, and only if, the Nth bit is set in
  532.      all the arguments.  ("Set" means that the value of the bit is 1
  533.      rather than 0.)
  534.  
  535.      For example, using 4-bit binary numbers, the "logical and" of 13
  536.      and 12 is 12: 1101 combined with 1100 produces 1100.
  537.  
  538.      In both the binary numbers, the leftmost two bits are set (i.e.,
  539.      they are 1's), so the leftmost two bits of the returned value are
  540.      set.  However, for the rightmost two bits, each is zero in at
  541.      least one of the arguments, so the rightmost two bits of the
  542.      returned value are 0's.
  543.  
  544.      Therefore,
  545.  
  546.           (logand 13 12)
  547.                => 12
  548.  
  549.      If `logand' is not passed any argument, it returns a value of -1.
  550.      This number is an identity element for `logand' because its binary
  551.      representation consists entirely of ones.  If `logand' is passed
  552.      just one argument, it returns that argument.
  553.  
  554.           ;                24-bit binary values
  555.           
  556.           (logand 14 13)     ; 14  =  0000 0000  0000 0000  0000 1110
  557.                              ; 13  =  0000 0000  0000 0000  0000 1101
  558.                => 12         ; 12  =  0000 0000  0000 0000  0000 1100
  559.  
  560.           (logand 14 13 4)   ; 14  =  0000 0000  0000 0000  0000 1110
  561.                              ; 13  =  0000 0000  0000 0000  0000 1101
  562.                              ;  4  =  0000 0000  0000 0000  0000 0100
  563.                => 4          ;  4  =  0000 0000  0000 0000  0000 0100
  564.  
  565.           (logand)
  566.                => -1         ; -1  =  1111 1111  1111 1111  1111 1111
  567.  
  568.  - Function: logior &rest INTS-OR-MARKERS
  569.      This function returns the "inclusive or" of its arguments: the Nth
  570.      bit is set in the result if, and only if, the Nth bit is set in at
  571.      least one of the arguments.  If there are no arguments, the result
  572.      is zero, which is an identity element for this operation.  If
  573.      `logior' is passed just one argument, it returns that argument.
  574.  
  575.           ;               24-bit binary values
  576.           
  577.           (logior 12 5)      ; 12  =  0000 0000  0000 0000  0000 1100
  578.                              ;  5  =  0000 0000  0000 0000  0000 0101
  579.                => 13         ; 13  =  0000 0000  0000 0000  0000 1101
  580.  
  581.           (logior 12 5 7)    ; 12  =  0000 0000  0000 0000  0000 1100
  582.                              ;  5  =  0000 0000  0000 0000  0000 0101
  583.                              ;  7  =  0000 0000  0000 0000  0000 0111
  584.                => 15         ; 15  =  0000 0000  0000 0000  0000 1111
  585.  
  586.  - Function: logxor &rest INTS-OR-MARKERS
  587.      This function returns the "exclusive or" of its arguments: the Nth
  588.      bit is set in the result if, and only if, the Nth bit is set in an
  589.      odd number of the arguments.  If there are no arguments, the
  590.      result is 0.  If `logxor' is passed just one argument, it returns
  591.      that argument.
  592.  
  593.           ;               24-bit binary values
  594.           
  595.           (logxor 12 5)      ; 12  =  0000 0000  0000 0000  0000 1100
  596.                              ;  5  =  0000 0000  0000 0000  0000 0101
  597.                => 9          ;  9  =  0000 0000  0000 0000  0000 1001
  598.  
  599.           (logxor 12 5 7)    ; 12  =  0000 0000  0000 0000  0000 1100
  600.                              ;  5  =  0000 0000  0000 0000  0000 0101
  601.                              ;  7  =  0000 0000  0000 0000  0000 0111
  602.                => 14         ; 14  =  0000 0000  0000 0000  0000 1110
  603.  
  604.  - Function: lognot INTEGER
  605.      This function returns the logical complement of its argument: the
  606.      Nth bit is one in the result if, and only if, the Nth bit is zero
  607.      in INTEGER, and vice-versa.
  608.  
  609.           ;;  5  =  0000 0000  0000 0000  0000 0101
  610.           ;; becomes
  611.           ;; -6  =  1111 1111  1111 1111  1111 1010
  612.           
  613.           (lognot 5)
  614.                => -6
  615.  
  616. 
  617. File: elisp,  Node: Transcendental Functions,  Next: Random Numbers,  Prev: Bitwise Operations,  Up: Numbers
  618.  
  619. Transcendental Functions
  620. ========================
  621.  
  622.    These mathematical functions are available if floating point is
  623. supported.  They allow integers as well as floating point numbers as
  624. arguments.
  625.  
  626.  - Function: sin ARG
  627.  - Function: cos ARG
  628.  - Function: tan ARG
  629.      These are the ordinary trigonometric functions, with argument
  630.      measured in radians.
  631.  
  632.  - Function: asin ARG
  633.      The value of `(asin ARG)' is a number between - pi / 2 and pi / 2
  634.      (inclusive) whose sine is ARG; if, however, ARG is out of range
  635.      (outside [-1, 1]), then the result is a NaN.
  636.  
  637.  - Function: acos ARG
  638.      The value of `(acos ARG)' is a number between 0 and pi (inclusive)
  639.      whose cosine is ARG; if, however, ARG is out of range (outside
  640.      [-1, 1]), then the result is a NaN.
  641.  
  642.  - Function: atan ARG
  643.      The value of `(atan ARG)' is a number between - pi / 2 and pi / 2
  644.      (exclusive) whose tangent is ARG.
  645.  
  646.  - Function: exp ARG
  647.      This is the exponential function; it returns e to the power ARG.
  648.  
  649.  - Function: log ARG &optional BASE
  650.      This function returns the logarithm of ARG, with base BASE.  If
  651.      you don't specify BASE, the base E is used.  If ARG is negative,
  652.      the result is a NaN.
  653.  
  654.  - Function: log10 ARG
  655.      This function returns the logarithm of ARG, with base 10.  If ARG
  656.      is negative, the result is a NaN.
  657.  
  658.  - Function: expt X Y
  659.      This function returns X raised to power Y.
  660.  
  661.  - Function: sqrt ARG
  662.      This returns the square root of ARG.
  663.  
  664. 
  665. File: elisp,  Node: Random Numbers,  Prev: Transcendental Functions,  Up: Numbers
  666.  
  667. Random Numbers
  668. ==============
  669.  
  670.    In a computer, a series of pseudo-random numbers is generated in a
  671. deterministic fashion.  The numbers are not truly random, but they have
  672. certain properties that mimic a random series.  For example, all
  673. possible values occur equally often in a pseudo-random series.
  674.  
  675.    In Emacs, pseudo-random numbers are generated from a "seed" number.
  676. Starting from any given seed, the `random' function always generates
  677. the same sequence of numbers.  Emacs always starts with the same seed
  678. value, so the sequence of values of `random' is actually the same in
  679. each Emacs run!  For example, in one operating system, the first call
  680. to `(random)' after you start Emacs always returns -1457731, and the
  681. second one always returns -7692030.  This is helpful for debugging.
  682.  
  683.    If you want truly unpredictable random numbers, execute `(random
  684. t)'.  This chooses a new seed based on the current time of day and on
  685. Emacs' process ID number.
  686.  
  687.  - Function: random &optional LIMIT
  688.      This function returns a pseudo-random integer.  When called more
  689.      than once, it returns a series of pseudo-random integers.
  690.  
  691.      If LIMIT is `nil', then the value may in principle be any integer.
  692.      If LIMIT is a positive integer, the value is chosen to be
  693.      nonnegative and less than LIMIT (only in Emacs 19).
  694.  
  695.      If LIMIT is `t', it means to choose a new seed based on the
  696.      current time of day and on Emacs's process ID number.
  697.  
  698.      On some machines, any integer representable in Lisp may be the
  699.      result of `random'.  On other machines, the result can never be
  700.      larger than a certain maximum or less than a certain (negative)
  701.      minimum.
  702.  
  703. 
  704. File: elisp,  Node: Strings and Characters,  Next: Lists,  Prev: Numbers,  Up: Top
  705.  
  706. Strings and Characters
  707. **********************
  708.  
  709.    A string in Emacs Lisp is an array that contains an ordered sequence
  710. of characters.  Strings are used as names of symbols, buffers, and
  711. files, to send messages to users, to hold text being copied between
  712. buffers, and for many other purposes.  Because strings are so
  713. important, many functions are provided expressly for manipulating them.
  714. Emacs Lisp programs use strings more often than individual characters.
  715.  
  716. * Menu:
  717.  
  718. * Intro to Strings::          Basic properties of strings and characters.
  719. * Predicates for Strings::    Testing whether an object is a string or char.
  720. * Creating Strings::          Functions to allocate new strings.
  721. * Text Comparison::           Comparing characters or strings.
  722. * String Conversion::         Converting characters or strings and vice versa.
  723. * Formatting Strings::        `format': Emacs's analog of `printf'.
  724. * Character Case::            Case conversion functions.
  725. * Case Table::              Customizing case conversion.
  726.  
  727.    *Note Strings of Events::, for special considerations when using
  728. strings of keyboard character events.
  729.  
  730. 
  731. File: elisp,  Node: Intro to Strings,  Next: Predicates for Strings,  Up: Strings and Characters
  732.  
  733. Introduction to Strings and Characters
  734. ======================================
  735.  
  736.    Strings in Emacs Lisp are arrays that contain an ordered sequence of
  737. characters.  Characters are represented in Emacs Lisp as integers;
  738. whether an integer was intended as a character or not is determined only
  739. by how it is used.  Thus, strings really contain integers.
  740.  
  741.    The length of a string (like any array) is fixed and independent of
  742. the string contents, and cannot be altered.  Strings in Lisp are *not*
  743. terminated by a distinguished character code.  (By contrast, strings in
  744. C are terminated by a character with ASCII code 0.) This means that any
  745. character, including the null character (ASCII code 0), is a valid
  746. element of a string.
  747.  
  748.    Since strings are considered arrays, you can operate on them with the
  749. general array functions.  (*Note Sequences Arrays Vectors::.)  For
  750. example, you can access or change individual characters in a string
  751. using the functions `aref' and `aset' (*note Array Functions::.).
  752.  
  753.    Each character in a string is stored in a single byte.  Therefore,
  754. numbers not in the range 0 to 255 are truncated when stored into a
  755. string.  This means that a string takes up much less memory than a
  756. vector of the same length.
  757.  
  758.    Sometimes key sequences are represented as strings.  When a string is
  759. a key sequence, string elements in the range 128 to 255 represent meta
  760. characters (which are extremely large integers) rather than keyboard
  761. events in the range 128 to 255.
  762.  
  763.    Strings cannot hold characters that have the hyper, super or alt
  764. modifiers; they can hold ASCII control characters, but no others.  They
  765. do not distinguish case in ASCII control characters.  *Note Character
  766. Type::, for more information about representation of meta and other
  767. modifiers for keyboard input characters.
  768.  
  769.    Like a buffer, a string can contain text properties for the
  770. characters in it, as well as the characters themselves.  *Note Text
  771. Properties::.
  772.  
  773.    *Note Text::, for information about functions that display strings or
  774. copy them into buffers.  *Note Character Type::, and *Note String
  775. Type::, for information about the syntax of characters and strings.
  776.  
  777. 
  778. File: elisp,  Node: Predicates for Strings,  Next: Creating Strings,  Prev: Intro to Strings,  Up: Strings and Characters
  779.  
  780. The Predicates for Strings
  781. ==========================
  782.  
  783.    For more information about general sequence and array predicates,
  784. see *Note Sequences Arrays Vectors::, and *Note Arrays::.
  785.  
  786.  - Function: stringp OBJECT
  787.      This function returns `t' if OBJECT is a string, `nil' otherwise.
  788.  
  789.  - Function: char-or-string-p OBJECT
  790.      This function returns `t' if OBJECT is a string or a character
  791.      (i.e., an integer), `nil' otherwise.
  792.  
  793. 
  794. File: elisp,  Node: Creating Strings,  Next: Text Comparison,  Prev: Predicates for Strings,  Up: Strings and Characters
  795.  
  796. Creating Strings
  797. ================
  798.  
  799.    The following functions create strings, either from scratch, or by
  800. putting strings together, or by taking them apart.
  801.  
  802.  - Function: make-string COUNT CHARACTER
  803.      This function returns a string made up of COUNT repetitions of
  804.      CHARACTER.  If COUNT is negative, an error is signaled.
  805.  
  806.           (make-string 5 ?x)
  807.                => "xxxxx"
  808.           (make-string 0 ?x)
  809.                => ""
  810.  
  811.      Other functions to compare with this one include `char-to-string'
  812.      (*note String Conversion::.), `make-vector' (*note Vectors::.), and
  813.      `make-list' (*note Building Lists::.).
  814.  
  815.  - Function: substring STRING START &optional END
  816.      This function returns a new string which consists of those
  817.      characters from STRING in the range from (and including) the
  818.      character at the index START up to (but excluding) the character
  819.      at the index END.  The first character is at index zero.
  820.  
  821.           (substring "abcdefg" 0 3)
  822.                => "abc"
  823.  
  824.      Here the index for `a' is 0, the index for `b' is 1, and the index
  825.      for `c' is 2.  Thus, three letters, `abc', are copied from the
  826.      full string.  The index 3 marks the character position up to which
  827.      the substring is copied.  The character whose index is 3 is
  828.      actually the fourth character in the string.
  829.  
  830.      A negative number counts from the end of the string, so that -1
  831.      signifies the index of the last character of the string.  For
  832.      example:
  833.  
  834.           (substring "abcdefg" -3 -1)
  835.                => "ef"
  836.  
  837.      In this example, the index for `e' is -3, the index for `f' is -2,
  838.      and the index for `g' is -1.  Therefore, `e' and `f' are included,
  839.      and `g' is excluded.
  840.  
  841.      When `nil' is used as an index, it falls after the last character
  842.      in the string.  Thus:
  843.  
  844.           (substring "abcdefg" -3 nil)
  845.                => "efg"
  846.  
  847.      Omitting the argument END is equivalent to specifying `nil'.  It
  848.      follows that `(substring STRING 0)' returns a copy of all of
  849.      STRING.
  850.  
  851.           (substring "abcdefg" 0)
  852.                => "abcdefg"
  853.  
  854.      But we recommend `copy-sequence' for this purpose (*note Sequence
  855.      Functions::.).
  856.  
  857.      A `wrong-type-argument' error is signaled if either START or END
  858.      are non-integers.  An `args-out-of-range' error is signaled if
  859.      START indicates a character following END, or if either integer is
  860.      out of range for STRING.
  861.  
  862.      Contrast this function with `buffer-substring' (*note Buffer
  863.      Contents::.), which returns a string containing a portion of the
  864.      text in the current buffer.  The beginning of a string is at index
  865.      0, but the beginning of a buffer is at index 1.
  866.  
  867.  - Function: concat &rest SEQUENCES
  868.      This function returns a new string consisting of the characters in
  869.      the arguments passed to it.  The arguments may be strings, lists
  870.      of numbers, or vectors of numbers; they are not themselves
  871.      changed.  If no arguments are passed to `concat', it returns an
  872.      empty string.
  873.  
  874.           (concat "abc" "-def")
  875.                => "abc-def"
  876.           (concat "abc" (list 120 (+ 256 121)) [122])
  877.                => "abcxyz"
  878.           (concat "The " "quick brown " "fox.")
  879.                => "The quick brown fox."
  880.           (concat)
  881.                => ""
  882.  
  883.      The second example above shows how characters stored in strings are
  884.      taken modulo 256.  In other words, each character in the string is
  885.      stored in one byte.
  886.  
  887.      The `concat' function always constructs a new string that is not
  888.      `eq' to any existing string.
  889.  
  890.      When an argument is an integer (not a sequence of integers), it is
  891.      converted to a string of digits making up the decimal printed
  892.      representation of the integer.  This special case exists for
  893.      compatibility with Mocklisp, and we don't recommend you take
  894.      advantage of it.  If you want to convert an integer in this way,
  895.      use `format' (*note Formatting Strings::.) or `int-to-string'
  896.      (*note String Conversion::.).
  897.  
  898.           (concat 137)
  899.                => "137"
  900.           (concat 54 321)
  901.                => "54321"
  902.  
  903.      For information about other concatenation functions, see the
  904.      description of `mapconcat' in *Note Mapping Functions::, `vconcat'
  905.      in *Note Vectors::, and `append' in *Note Building Lists::.
  906.  
  907. 
  908. File: elisp,  Node: Text Comparison,  Next: String Conversion,  Prev: Creating Strings,  Up: Strings and Characters
  909.  
  910. Comparison of Characters and Strings
  911. ====================================
  912.  
  913.  - Function: char-equal CHARACTER1 CHARACTER2
  914.      This function returns `t' if the arguments represent the same
  915.      character, `nil' otherwise.  This function ignores differences in
  916.      case if `case-fold-search' is non-`nil'.
  917.  
  918.           (char-equal ?x ?x)
  919.                => t
  920.           (char-to-string (+ 256 ?x))
  921.                => "x"
  922.           (char-equal ?x  (+ 256 ?x))
  923.                => t
  924.  
  925.  - Function: string= STRING1 STRING2
  926.      This function returns `t' if the characters of the two strings
  927.      match exactly; case is significant.
  928.  
  929.           (string= "abc" "abc")
  930.                => t
  931.           (string= "abc" "ABC")
  932.                => nil
  933.           (string= "ab" "ABC")
  934.                => nil
  935.  
  936.  - Function: string-equal STRING1 STRING2
  937.      `string-equal' is another name for `string='.
  938.  
  939.  - Function: string< STRING1 STRING2
  940.      This function compares two strings a character at a time.  First it
  941.      scans both the strings at once to find the first pair of
  942.      corresponding characters that do not match.  If the lesser
  943.      character of those two is the character from STRING1, then STRING1
  944.      is less, and this function returns `t'.  If the lesser character
  945.      is the one from STRING2, then STRING1 is greater, and this
  946.      function returns `nil'.  If the two strings match entirely, the
  947.      value is `nil'.
  948.  
  949.      Pairs of characters are compared by their ASCII codes.  Keep in
  950.      mind that lower case letters have higher numeric values in the
  951.      ASCII character set than their upper case counterparts; numbers and
  952.      many punctuation characters have a lower numeric value than upper
  953.      case letters.
  954.  
  955.           (string< "abc" "abd")
  956.                => t
  957.           (string< "abd" "abc")
  958.                => nil
  959.           (string< "123" "abc")
  960.                => t
  961.  
  962.      When the strings have different lengths, and they match up to the
  963.      length of STRING1, then the result is `t'.  If they match up to
  964.      the length of STRING2, the result is `nil'.  A string without any
  965.      characters in it is the smallest possible string.
  966.  
  967.           (string< "" "abc")
  968.                => t
  969.           (string< "ab" "abc")
  970.                => t
  971.           (string< "abc" "")
  972.                => nil
  973.           (string< "abc" "ab")
  974.                => nil
  975.           (string< "" "")
  976.                => nil
  977.  
  978.  - Function: string-lessp STRING1 STRING2
  979.      `string-lessp' is another name for `string<'.
  980.  
  981.    See `compare-buffer-substrings' in *Note Comparing Text::, for a way
  982. to compare text in buffers.
  983.  
  984. 
  985. File: elisp,  Node: String Conversion,  Next: Formatting Strings,  Prev: Text Comparison,  Up: Strings and Characters
  986.  
  987. Conversion of Characters and Strings
  988. ====================================
  989.  
  990.    Characters and strings may be converted into each other and into
  991. integers.  `format' and `prin1-to-string' (*note Output Functions::.)
  992. may also be used to convert Lisp objects into strings.
  993. `read-from-string' (*note Input Functions::.) may be used to "convert"
  994. a string representation of a Lisp object into an object.
  995.  
  996.    *Note Documentation::, for a description of functions which return a
  997. string representing the Emacs standard notation of the argument
  998. character (`single-key-description' and `text-char-description').
  999. These functions are used primarily for printing help messages.
  1000.  
  1001.  - Function: char-to-string CHARACTER
  1002.      This function returns a new string with a length of one character.
  1003.      The value of CHARACTER, modulo 256, is used to initialize the
  1004.      element of the string.
  1005.  
  1006.      This function is similar to `make-string' with an integer argument
  1007.      of 1.  (*Note Creating Strings::.)  This conversion can also be
  1008.      done with `format' using the `%c' format specification.  (*Note
  1009.      Formatting Strings::.)
  1010.  
  1011.           (char-to-string ?x)
  1012.                => "x"
  1013.           (char-to-string (+ 256 ?x))
  1014.                => "x"
  1015.           (make-string 1 ?x)
  1016.                => "x"
  1017.  
  1018.  - Function: string-to-char STRING
  1019.      This function returns the first character in STRING.  If the
  1020.      string is empty, the function returns 0.  The value is also 0 when
  1021.      the first character of STRING is the null character, ASCII code 0.
  1022.  
  1023.           (string-to-char "ABC")
  1024.                => 65
  1025.           (string-to-char "xyz")
  1026.                => 120
  1027.           (string-to-char "")
  1028.                => 0
  1029.           (string-to-char "\000")
  1030.                => 0
  1031.  
  1032.      This function may be eliminated in the future if it does not seem
  1033.      useful enough to retain.
  1034.  
  1035.  - Function: number-to-string NUMBER
  1036.  - Function: int-to-string NUMBER
  1037.      This function returns a string consisting of the printed
  1038.      representation of NUMBER, which may be an integer or a floating
  1039.      point number.  The value starts with a sign if the argument is
  1040.      negative.
  1041.  
  1042.           (int-to-string 256)
  1043.                => "256"
  1044.           (int-to-string -23)
  1045.                => "-23"
  1046.           (int-to-string -23.5)
  1047.                => "-23.5"
  1048.  
  1049.      See also the function `format' in *Note Formatting Strings::.
  1050.  
  1051.  - Function: string-to-number STRING
  1052.  - Function: string-to-int STRING
  1053.      This function returns the integer value of the characters in
  1054.      STRING, read as a number in base ten.  It skips spaces at the
  1055.      beginning of STRING, then reads as much of STRING as it can
  1056.      interpret as a number.  (On some systems it ignores other
  1057.      whitespace at the beginning, not just spaces.)  If the first
  1058.      character after the ignored whitespace is not a digit or a minus
  1059.      sign, this function returns 0.
  1060.  
  1061.           (string-to-number "256")
  1062.                => 256
  1063.           (string-to-number "25 is a perfect square.")
  1064.                => 25
  1065.           (string-to-number "X256")
  1066.                => 0
  1067.           (string-to-number "-4.5")
  1068.                => -4.5
  1069.  
  1070. 
  1071. File: elisp,  Node: Formatting Strings,  Next: Character Case,  Prev: String Conversion,  Up: Strings and Characters
  1072.  
  1073. Formatting Strings
  1074. ==================
  1075.  
  1076.    "Formatting" means constructing a string by substitution of computed
  1077. values at various places in a constant string.  This string controls
  1078. how the other values are printed as well as where they appear; it is
  1079. called a "format string".
  1080.  
  1081.    Formatting is often useful for computing messages to be displayed.
  1082. In fact, the functions `message' and `error' provide the same
  1083. formatting feature described here; they differ from `format' only in
  1084. how they use the result of formatting.
  1085.  
  1086.  - Function: format STRING &rest OBJECTS
  1087.      This function returns a new string that is made by copying STRING
  1088.      and then replacing any format specification in the copy with
  1089.      encodings of the corresponding OBJECTS.  The arguments OBJECTS are
  1090.      the computed values to be formatted.
  1091.  
  1092.    A format specification is a sequence of characters beginning with a
  1093. `%'.  Thus, if there is a `%d' in STRING, the `format' function
  1094. replaces it with the printed representation of one of the values to be
  1095. formatted (one of the arguments OBJECTS).  For example:
  1096.  
  1097.      (format "The value of fill-column is %d." fill-column)
  1098.           => "The value of fill-column is 72."
  1099.  
  1100.    If STRING contains more than one format specification, the format
  1101. specifications are matched with successive values from OBJECTS.  Thus,
  1102. the first format specification in STRING is matched with the first such
  1103. value, the second format specification is matched with the second such
  1104. value, and so on.  Any extra format specifications (those for which
  1105. there are no corresponding values) cause unpredictable behavior.  Any
  1106. extra values to be formatted will be ignored.
  1107.  
  1108.    Certain format specifications require values of particular types.
  1109. However, no error is signaled if the value actually supplied fails to
  1110. have the expected type.  Instead, the output is likely to be
  1111. meaningless.
  1112.  
  1113.    Here is a table of the characters that can follow `%' to make up a
  1114. format specification:
  1115.  
  1116. `s'
  1117.      Replace the specification with the printed representation of the
  1118.      object, made without quoting.  Thus, strings are represented by
  1119.      their contents alone, with no `"' characters, and symbols appear
  1120.      without `\' characters.
  1121.  
  1122.      If there is no corresponding object, the empty string is used.
  1123.  
  1124. `S'
  1125.      Replace the specification with the printed representation of the
  1126.      object, made with quoting.  Thus, strings are enclosed in `"'
  1127.      characters, and `\' characters appear where necessary before
  1128.      special characters.
  1129.  
  1130.      If there is no corresponding object, the empty string is used.
  1131.  
  1132. `o'
  1133.      Replace the specification with the base-eight representation of an
  1134.      integer.
  1135.  
  1136. `d'
  1137.      Replace the specification with the base-ten representation of an
  1138.      integer.
  1139.  
  1140. `x'
  1141.      Replace the specification with the base-sixteen representation of
  1142.      an integer.
  1143.  
  1144. `c'
  1145.      Replace the specification with the character which is the value
  1146.      given.
  1147.  
  1148. `e'
  1149.      Replace the specification with the exponential notation for a
  1150.      floating point number.
  1151.  
  1152. `f'
  1153.      Replace the specification with the decimal-point notation for a
  1154.      floating point number.
  1155.  
  1156. `g'
  1157.      Replace the specification with notation for a floating point
  1158.      number, using either exponential notation or decimal-point
  1159.      notation whichever is shorter.
  1160.  
  1161. `%'
  1162.      A single `%' is placed in the string.  This format specification is
  1163.      unusual in that it does not use a value.  For example, `(format "%%
  1164.      %d" 30)' returns `"% 30"'.
  1165.  
  1166.    Any other format character results in an `Invalid format operation'
  1167. error.
  1168.  
  1169.    Here are several examples:
  1170.  
  1171.      (format "The name of this buffer is %s." (buffer-name))
  1172.           => "The name of this buffer is strings.texi."
  1173.      
  1174.      (format "The buffer object prints as %s." (current-buffer))
  1175.           => "The buffer object prints as #<buffer strings.texi>."
  1176.      
  1177.      (format "The octal value of 18 is %o,
  1178.               and the hex value is %x." 18 18)
  1179.           => "The octal value of 18 is 22,
  1180.               and the hex value is 12."
  1181.  
  1182.    All the specification characters allow an optional numeric prefix
  1183. between the `%' and the character.  The optional numeric prefix defines
  1184. the minimum width for the object.  If the printed representation of the
  1185. object contains fewer characters than this, then it is padded.  The
  1186. padding is on the left if the prefix is positive (or starts with zero)
  1187. and on the right if the prefix is negative.  The padding character is
  1188. normally a space, but if the numeric prefix starts with a zero, zeros
  1189. are used for padding.
  1190.  
  1191.      (format "%06d will be padded on the left with zeros" 123)
  1192.           => "000123 will be padded on the left with zeros"
  1193.      
  1194.      (format "%-6d will be padded on the right" 123)
  1195.           => "123    will be padded on the right"
  1196.  
  1197.    `format' never truncates an object's printed representation, no
  1198. matter what width you specify.  Thus, you can use a numeric prefix to
  1199. specify a minimum spacing between columns with no risk of losing
  1200. information.
  1201.  
  1202.    In the following three examples, `%7s' specifies a minimum width of
  1203. 7.  In the first case, the string inserted in place of `%7s' has only 3
  1204. letters, so 4 blank spaces are inserted for padding.  In the second
  1205. case, the string `"specification"' is 13 letters wide but is not
  1206. truncated.  In the third case, the padding is on the right.
  1207.  
  1208.      (format "The word `%7s' actually has %d letters in it." "foo"
  1209.              (length "foo"))
  1210.           => "The word `    foo' actually has 3 letters in it."
  1211.  
  1212.      (format "The word `%7s' actually has %d letters in it."
  1213.              "specification"
  1214.              (length "specification"))
  1215.           => "The word `specification' actually has 13 letters in it."
  1216.  
  1217.      (format "The word `%-7s' actually has %d letters in it." "foo"
  1218.              (length "foo"))
  1219.           => "The word `foo    ' actually has 3 letters in it."
  1220.  
  1221. 
  1222. File: elisp,  Node: Character Case,  Next: Case Table,  Prev: Formatting Strings,  Up: Strings and Characters
  1223.  
  1224. Character Case
  1225. ==============
  1226.  
  1227.    The character case functions change the case of single characters or
  1228. of the contents of strings.  The functions convert only alphabetic
  1229. characters (the letters `A' through `Z' and `a' through `z'); other
  1230. characters are not altered.  The functions do not modify the strings
  1231. that are passed to them as arguments.
  1232.  
  1233.    The examples below use the characters `X' and `x' which have ASCII
  1234. codes 88 and 120 respectively.
  1235.  
  1236.  - Function: downcase STRING-OR-CHAR
  1237.      This function converts a character or a string to lower case.
  1238.  
  1239.      When the argument to `downcase' is a string, the function creates
  1240.      and returns a new string in which each letter in the argument that
  1241.      is upper case is converted to lower case.  When the argument to
  1242.      `downcase' is a character, `downcase' returns the corresponding
  1243.      lower case character.  This value is an integer.  If the original
  1244.      character is lower case, or is not a letter, then the value equals
  1245.      the original character.
  1246.  
  1247.           (downcase "The cat in the hat")
  1248.                => "the cat in the hat"
  1249.           
  1250.           (downcase ?X)
  1251.                => 120
  1252.  
  1253.  - Function: upcase STRING-OR-CHAR
  1254.      This function converts a character or a string to upper case.
  1255.  
  1256.      When the argument to `upcase' is a string, the function creates
  1257.      and returns a new string in which each letter in the argument that
  1258.      is lower case is converted to upper case.
  1259.  
  1260.      When the argument to `upcase' is a character, `upcase' returns the
  1261.      corresponding upper case character.  This value is an integer.  If
  1262.      the original character is upper case, or is not a letter, then the
  1263.      value equals the original character.
  1264.  
  1265.           (upcase "The cat in the hat")
  1266.                => "THE CAT IN THE HAT"
  1267.           
  1268.           (upcase ?x)
  1269.                => 88
  1270.  
  1271.  - Function: capitalize STRING-OR-CHAR
  1272.      This function capitalizes strings or characters.  If
  1273.      STRING-OR-CHAR is a string, the function creates and returns a new
  1274.      string, whose contents are a copy of STRING-OR-CHAR in which each
  1275.      word has been capitalized.  This means that the first character of
  1276.      each word is converted to upper case, and the rest are converted
  1277.      to lower case.
  1278.  
  1279.      The definition of a word is any sequence of consecutive characters
  1280.      that are assigned to the word constituent category in the current
  1281.      syntax table (*Note Syntax Class Table::).
  1282.  
  1283.      When the argument to `capitalize' is a character, `capitalize' has
  1284.      the same result as `upcase'.
  1285.  
  1286.           (capitalize "The cat in the hat")
  1287.                => "The Cat In The Hat"
  1288.           
  1289.           (capitalize "THE 77TH-HATTED CAT")
  1290.                => "The 77th-Hatted Cat"
  1291.           
  1292.           (capitalize ?x)
  1293.                => 88
  1294.  
  1295.